
import java.io.BufferedOutputStream;
import java.io.DataOutputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;


public class WriteToFile implements IWriter 
{
    private DataOutputStream out_stream;//static
    private String output_file_name = "/home/tatyana/Documents/File_for_compressor/Statistic";
    public void OpenWriter()
    {
        try
        {        
            out_stream = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(output_file_name)));
        }
        catch(FileNotFoundException ex)
        {
            System.out.print("File " + output_file_name + " not found exception: " + ex);
        }
        catch(IOException ex)
        {
            System.out.print("Input/Output exception for open file " + output_file_name + ex);
        }
    }
    public void CloseWriter()
    {
        try
        {
            out_stream.close();
         }
        catch(IOException ex)
        {
            System.out.print("Input/Output exception: " + ex);
        }
    }
    public void WriteFile(TFile file)
    {
        try
        {
            out_stream.write(("\n\n\t\t" + file.getcontent() + 
                                "\n\t\t" + file.getlanguage() +
                                "\n\t\t" + file.gettype()).getBytes());
            out_stream.flush();
        }
        catch(IOException ex)
        {
            System.out.print("Input/Output exception: " + ex);
        }
    }
    public void WriteArchiveFile(TFile file, String compressor_name, long arch_file_size, int ratio, long time, String compression_level)
    {
        try
        {
            out_stream.write(("\n\t\t" + compressor_name + 
                                "\t\t" + arch_file_size + " bytes" + 
                                "\t\t" + ratio + "%" +
                                "\t\t" + time + 
                                "\t\t" + compression_level).getBytes());
            out_stream.flush();
        }
        catch(IOException ex)
        {
            System.out.print("Input/Output exception: " + ex);
        }
    }
    public void WriteCryptoFile(TFile file, String crypto_algorithm, long crypto_file_size, String mode)
    {
        try
        {
            out_stream.write(("\n\t\t" + crypto_algorithm + 
                                "\t\t" + crypto_file_size + " bytes" + 
                                "\t\t" + mode).getBytes());
            out_stream.flush();
        }
        catch(IOException ex)
        {
            System.out.print("Input/Output exception: " + ex);
        }
    }
    public void WriteArchiveCryptoFile(String compressor_name, long archive_crypto_file_size, int ratio, long time)
    {
        try
        {
            out_stream.write(("\n\t\t" + compressor_name + 
                                "\t\t" + archive_crypto_file_size + " bytes" +
                                "\t\t" + ratio + "%" +
                                "\t\t" + time + "ms").getBytes());
            out_stream.flush();
        }
        catch(IOException ex)
        {
            System.out.print("Input/Output exception: " + ex);
        }
    }
    
}
